home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2308 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  69 lines

  1. Path: news.pi.net!news
  2. From: mv@pi.net
  3. Newsgroups: comp.lang.c
  4. Subject: ** Array problem **
  5. Date: 20 Jan 1996 10:47:48 GMT
  6. Organization: IBM OS/2 Warp
  7. Message-ID: <4dqh8k$ov9@neptunus.pi.net>
  8. Reply-To: mv@pi.net
  9. NNTP-Posting-Host: asd44.pi.net
  10. X-Newsreader: IBM NewsReader/2 v1.03
  11.  
  12.  
  13. Hello Bill Wendlig (and everybody else),
  14.  
  15.  
  16. A couple a days ago you replied to a message from me about some
  17. problems with a piece if code..
  18. You handed me some tips and corrections about a double indexed array that
  19. turned out to be a 3-dimensional one..
  20.  
  21. I implemented you corrections but to no good, it made things even worse...
  22. But than again I'm not a an experienced C-programmer..
  23.  
  24. But could you please tell me why this code works...
  25.  
  26.  
  27. --------------------------------------------
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <malloc.h>
  33.  
  34.  
  35. char *s;
  36. char a[20][20];
  37.  
  38.  
  39.  
  40. int main (void)
  41.  
  42. {
  43.  int i=0;
  44.  
  45.   s=(char *)malloc(18);
  46.    strcpy(s,"Blah blah, this works");
  47.     for (i=0; i<=15; i++)
  48.      {
  49.       strcpy(a[i],s);
  50.      }
  51.     for (i=0; i<=15; i++)
  52.      {
  53.       printf("%s\n",a[i]);
  54.      }
  55.   free(s);
  56.  return 0;
  57. }
  58.  
  59. --------------------------------
  60.  
  61. This is the same situation but it works fine here ?!
  62.  
  63.  
  64.  
  65. TTYL,
  66.  
  67. Martijn Valkier.
  68.  
  69.